<template>
  <div class="advertise-box" v-if="advertise">
    <div class="ad-bg">
      <a
        target="_blank"
        :title="advdata.adv_title"
        class="inside-bg"
      >
        <img :src="advdata.adv_cover" alt="" />
      </a>
      <div class="ad" @click="closead">
        <span>广告<i class="iconfont icon-guanbi"></i></span>
      </div>
      <a :href="advdata.adv_herf" target="_blank" class="mask" @click="handerNum(advdata.adv_id)"></a>
    </div>
  </div>
</template>

<script>
import http from '@/util/http'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      advertise: true,
      advdata: {}
    }
  },
  mounted () {
    http.getHomePoster().then(res => {
      console.log(res.data)
      this.advdata = res.data.data
    })
  },
  computed: {
    ...mapState(['user'])
  },
  methods: {
    // 关闭广告
    closead () {
      this.advertise = false
    },
    // 记录数量
    handerNum (id) {
      console.log('记录广告数量')
      http.appendAdvNum(id, this.user.uid).then(res => {
        console.log(res.data)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
// 广告
.advertise-box {
  width: 100%;
  height: 100%;
  margin-bottom: 10px;
  position: relative;
  .ad-bg {
    width: 100%;
    height: 100%;
    position: relative;
    .inside-bg {
      width: 100%;
      img {
        display: block;
        width: 100%;
        object-fit: cover;
        border-radius: 5px;
      }
    }
    .ad {
      position: absolute;
      top: 0px;
      right: 0px;
      cursor: pointer;
      display: flex;
      align-items: center;
      z-index: 100;
      span {
        font-size: 12px;
        color: #333;
        background: #f5f5f5;
        opacity: 0.4;
        padding: 3px;
        text-align: center;
        border-radius: 0 6px 0 6px;

        i {
          font-size: 12px;
          color: #333;
          padding-left: 3px;
        }
      }
    }
  }
  .mask {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    &:hover {
      background: rgba(0, 0, 0, 0.15);
    }
  }
}
</style>
